package com.sansan.qiangji.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class JWTUtil {
    /**
     * 加密密钥
     */
    private static final String SECRET = "com.sansan.qiangji";

    public static String getJsonWebToken(String userName, String loginTime, String loginMethod) {
        return Jwts.builder().claim("userName", userName)
                .claim("loginTime", loginTime)
                .claim("loginMethod", loginMethod)
                .signWith(SignatureAlgorithm.HS256, SECRET).compact();
    }

    public static Claims checkJWT(String value) {
        try {
            return Jwts.parser().setSigningKey(SECRET).parseClaimsJws(value).getBody();
        } catch (Exception ignored) {
        }
        return null;
    }
}
